#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    ll t;
    scanf("%lld",&t);
    for(ll i=1;i<=t;i++){
        ll a,b,c,d,u,v,w,num;
        scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
        for(ll i=1;i<=a;i++){
            scanf("%lld %lld %lld",&u,&v,&w);
        }
        for(ll i=1;i<=b;i++){
            scanf("%lld %lld %lld",&u,&v,&w);
        }
        printf("%lld %lld\n",a,0LL);
    }
    return 0;
}
